﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LDSP.BRL;

namespace LDSP.UI.EnterpriseAdmin.Operation
{
    public partial class AddFavoritePublicInfo : BaseEnterpriseAdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    this.CheckQS();
                }
                if (this.RB())
                {
                    this.InitDataDynamicBefore();
                    if (!IsPostBack)
                    {
                        this.InitDataSelect();
                    }
                    this.InitDataDynamicAfter();
                }
            }
            catch (Exception ex)
            {
                this.HandlerException(ex);
            }
        }

        protected string TitleName = "法律法规";

        /// <summary>
        /// 源文档的类型
        /// </summary>
        protected DocType DocType
        {
            get { return (DocType)this.GetVSInt("LastID"); }
            set
            {
                this.SetVS("LastID", (int)value);
            }
        }

        protected void CheckQS()
        {
            DocType = (DocType)this.GetInt(this.Request.QueryString["docType"]);
            PageID = this.Request.QueryString["pageID"];
        }

        protected bool RB()
        {
            return true;
        }
        protected void SetStatus()
        {
            this.lbl_op.Text = "【添加】";
            this.lbl_op.Style["color"] = "red";
        }
        protected void InitDataSelect()
        {
            this.BindDDLPriority();
            this.SetStatus();
        }
        protected void InitDataDynamicBefore()
        {
            if (DocType == BRL.DocType.标准)
            {
                this.TitleName = "标准";
            }
        }
        protected void InitDataDynamicAfter()
        {
        }
        protected void BindDDLPriority()
        {
            this.ddl_priority.Items.Clear();
            this.ddl_priority.Items.Add(new ListItem(Priority.低.ToString(), ((int)Priority.低).ToString()));
            this.ddl_priority.Items.Add(new ListItem(Priority.中.ToString(), ((int)Priority.中).ToString()));
            this.ddl_priority.Items.Add(new ListItem(Priority.高.ToString(), ((int)Priority.高).ToString()));
            try
            {
                this.ddl_priority.SelectedIndex = 1;
            }
            catch { }
        }

        protected void ValidateDataBefore()
        {
        }
        protected void ValidateDataAfter()
        {
        }
        protected void SetData()
        {
            this.ValidateDataBefore();
            var publicFavoriteInfo = new PublicFavoriteInfo();
            publicFavoriteInfo.Priority = (Priority)this.GetInt(this.ddl_priority.SelectedValue);
            publicFavoriteInfo.Comment = this.txt_comment.Text;
            publicFavoriteInfo.Principal = this.txt_principal.Text.Trim();
            this.PublicFavoriteInfo(PageID, publicFavoriteInfo);
            this.ValidateDataAfter();
        }

        protected void btn_ok_Click(object sender, EventArgs e)
        {
            try
            {
                this.SetData();
                this.JSCloseWindow();
            }
            catch (Exception ex)
            {
                this.HandlerException(ex);
            }
        }   
    }
}